<?php
namespace app\run\model;

use think\Model;
use think\Db;
class ThemeProduct extends Model{
    /*
    * 专题商品的查询
    *@return array
    */
     public static function index($options){
        $res = Db::name('theme_product')->alias('a')
		->join('product b','a.product_id=b.id')
		->join('theme c','a.theme_id= c.id')
		->field('a.id,a.theme_id,a.product_id,b.name,c.name as cname')
        ->where('c.state',1)
        ->where('b.goods_state',1)
        // ->fetchSql(true)
		->paginate(5,false,$options);;
		return $res;
     }

     /*
     *专题商品的删除
     *@param array $where
     *@return int
     */

     public static function del(array $where){
         $res = Db::name('theme_product')->where($where)->delete();
         return $res;
     }


     /*
     *专题商品单条数据查询
     * @param array $where
     * @return array
     */
     public static function find($where){
         $res = Db::name('theme_product')->where($where)->find();
         return $res;
     }
     
     /*
     *专题商品添加
     * @param array $data
     * @return int
     */
     public static function theme_product(array $data){
        $res = Db::name('theme_product')->insert($data);
        return $res;

    }

    /*
    *专题商品修改
    *@param array $data
    *@return int
    */
    public static function updates(array $data){
        $res = Db::name('theme_product')->update($data);
        return $res;
    }

}